package filters.push;

import helper.PlanarImageWrapper;

import javax.media.jai.JAI;

import org.apache.log4j.Logger;

import at.fhv.framework.filter.PassivePushFilter;
import at.fhv.framework.interfaces.Push;

/**
 * The SourceFilter class.
 * 
 * @author Michael Sieber
 */
public class SourcePushFilter extends
		PassivePushFilter<PlanarImageWrapper, PlanarImageWrapper> {
	private static Logger LOGGER = Logger.getLogger(SourcePushFilter.class);
	private String _source;

	/**
	 * 
	 * @param source
	 */
	public SourcePushFilter(String source, Push<PlanarImageWrapper> target) {
		super(target);
		_source = source;
		execute(createEntity(), null);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected boolean execute(PlanarImageWrapper entity, PlanarImageWrapper data) {
		LOGGER.debug("Loading image: " + _source);
		entity.setImage(JAI.create("fileload", _source));
		_target.write(entity);
		return true;
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected PlanarImageWrapper createEntity() {
		return new PlanarImageWrapper();
	}
}
